package vlms.servlet;





import javax.servlet.ServletConfig;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import java.util.Calendar;

import vlms.cronjob.Fine;
import vlms.cronjob.Scheduler;
import vlms.cronjob.Subscription;
import vlms.util.*;
/**
 * Servlet implementation class StartUp
 */
public class StartUp extends HttpServlet {
	private final int noOfConn = 1000;
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StartUp() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		
		try{
			new JDBCConnectionDriver("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/vlmsdb", "root", "root", noOfConn);
			
			float finePerDayPerMovie = 5;
			Fine oFine = new Fine(finePerDayPerMovie);
			
			int renewalPeriodInDays = 30;
			Subscription oSubscription = new Subscription(renewalPeriodInDays);
			
			
			Calendar date = Calendar.getInstance();
			    
		    date.set(Calendar.HOUR, 0);
		    date.set(Calendar.MINUTE, 0);
		    date.set(Calendar.SECOND, 0);
		    date.set(Calendar.MILLISECOND, 0);
		    
		    int periodInHours = 24;
		    	
			Scheduler oScheduler = new Scheduler(date.getTime(),periodInHours,oFine,oSubscription);
			
			
//			System.out.println("HarryPotter1");
//			Connection[] c = new Connection[noOfConn];
//			for(int i=0;i<noOfConn;i++) {
//				
//				c[i] = DriverManager.getConnection("jdbc:user_mysql:");
//			}
//			
//			//sleep(60000);
//			
//			Statement stmt = c[0].createStatement();
//			
//			ResultSet rs = stmt.executeQuery("SELECT * from account");
//			
//			if(rs.next()) {
//				//rs.getString("username");
//				System.out.println(rs.getString("password"));
//			}
//			
//			for(int i=0;i<noOfConn;i++) {
//				
//				c[i].close();
//			}
		}
		catch(Exception e) {
			e.printStackTrace();
			System.out.println("HarryPotter" );
		}
		
		
		
	}

}
